/* 
* File:   Entry.cpp
* Author: Cody TV Weber
* 
* Created on March 18, 2014, 10:48 AM
*/

#include "./Entry.h"
#include "spamIndicatorEquation.h"

/*
*   Default Entry - At least needs a word.
*/
Entry::Entry(String^ word) {
	SetWord(word);
	this->totalNumberOfHam = 0;
	this->totalNumberOfSpam = 0;
	this->countInHam = 0;
	this->countInSpam = 0;
	this->percentageInHam = 0;
	this->percentageInSpam = 0;
	this->spamIndication = 0;
}

/*
* Designated constructor -
*      All constructors run through this constructor.
*/
Entry::Entry(String^ word, int countInHam, int countInSpam,int totalNumberOfHam, int totalNumberOfSpam, double percentageInHam, double percentageInSpam, double spamIndication) {
	SetWord(word);
	this->totalNumberOfHam = totalNumberOfHam;
	this->totalNumberOfSpam = totalNumberOfSpam;
	this->countInHam = countInHam;
	this->countInSpam = countInSpam;
	this->percentageInHam = percentageInHam;
	this->percentageInSpam = percentageInSpam;
	this->spamIndication = spamIndication;
}

/*
* Deconstructor -
*      Destroys all information of the object.
*/
Entry::~Entry() {
	this->word = "";
	this->countInHam = 0;
	this->countInSpam = 0;
	this->percentageInHam = 0;
	this->percentageInSpam = 0;
}

/*
* void Entry::calculateHamPercentage() -
*      Calculates the number of Ham emails that contain this entry out of all 
*      the Ham emails in the repository. Should be right before the 
*      calculateHamIndicator step.
*/
void Entry::calculateHamPercentage() {
	// Produces the percentage of occurrences in the Ham emails.
	if(getTotalNumberOfHam()!=0)
		percentageInHam = (this->GetCountInHam()*1.0 / this->getTotalNumberOfHam())*100;
	else
		percentageInHam = 0;
}

/*
* void Entry::calculateSpamPercentage() -
*      Calculates the number of Spam emails that contain this entry out of all 
*      the Spam emails in the repository.  Should be right before the 
*      calculateSpamIndicator step.
*/
void Entry::calculateSpamPercentage() {
	// Produces the percentage of occurrences in the Spam emails.
	if(getTotalNumberOfSpam()!=0)
		percentageInSpam = (this->GetCountInSpam()*1.0 / this->getTotalNumberOfSpam())*100;
	else
		percentageInSpam = 0;
}

/*
*void Entry::addHamOccurence() - 
*       Adds an occurrence of ham to the count of hams.  Should be apart of
*      the first step, indicating how many emails contain Ham.
*/
void Entry::addHamOccurrence() {
	this->SetCountInHam((this->GetCountInHam() + 1));
	this->calculateHamPercentage();
}

/*
*void Entry::addSpamOccurence() - 
*       Adds an occurrence of ham to the count of Spams.  Should be apart of
*      the first step, indicating how many emails contain Spam.
*/
void Entry::addSpamOccurrence() {
	this->SetCountInSpam((GetCountInSpam() + 1));
	this->calculateSpamPercentage();
}

/* 
* void Entry::calculatesSpamIndicator() -
*      Calculates the spamIndicator value for the Entry.  Should be the last
*      step before the entry is complete.
*/
void Entry::calculateSpamIndicator() {
	this->setSpamIndication(spamIndicatorEquation(this->GetPercentageInHam(), GetPercentageInSpam()));
}